@extends('Home.User.Common.layout')
@section('title')
    公司组织架构_设置
@endsection
@section('meta')
    <style>
        html, body {
            height: 100%;
            margin:0;padding:0;
            font-size: 12px;
        }
        div{
            -moz-box-sizing: border-box;  /*Firefox3.5+*/
            -webkit-box-sizing: border-box; /*Safari3.2+*/
            -o-box-sizing: border-box; /*Opera9.6*/
            -ms-box-sizing: border-box; /*IE8*/
            box-sizing: border-box; /*W3C标准(IE9+，Safari5.1+,Chrome10.0+,Opera10.6+都符合box-sizing的w3c标准语法)*/
        }
        .rt{
            margin-right: 0 !important;
        }
    </style>
@endsection
@section('content')
    <main class="common_content">
        <div class="container">
            <div class="ct_main">
                @include('Home.User.Set.Common.set_menu')
                <ul class="nav-items1 nav-items2 w999" id="tab-content2">
                    <!--基本设置-->
                    <li class="basic-sets active">
                        <div class="selector-head">
                            <h2>基本设置</h2>
                        </div>
                        <!--公司组织架构-->
                        <ul class="basic-sets-ul">
                            <li>
                                <h2 class="basic-title">
                                    职级权限对应说明
                                </h2>
                                <div class="layui-form">
                                    <table class="layui-table">
                                        <thead>
                                        <tr>
                                            <th>职级对应权限</th>
                                            <th>超级管理员</th>
                                            <th>管理员</th>
                                            <th>员工用户</th>
                                            <th>外部资源</th>
                                            <th>推荐用户</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>Manager</td>
                                            <td>√</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>×</td>
                                        </tr>
                                        <tr>
                                            <td>主管/leader</td>
                                            <td>×</td>
                                            <td>√</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>×</td>
                                        </tr>
                                        <tr>
                                            <td>员工</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>√</td>
                                            <td>×</td>
                                            <td>×</td>
                                        </tr>
                                        <tr>
                                            <td>外部资源</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>√</td>
                                            <td>×</td>
                                        </tr>
                                        <tr>
                                            <td>推荐用户</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>×</td>
                                            <td>√</td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </li>

                            <li>
                                <h2 class="basic-title" id="selector5">
                                    公司组织架构
                                    <div class="rt">
                                        <a href="javacsript:;" class="add-new-btn" title="添加经理" onclick="open_button('{{route('frame_admin_add')}}','添加经理')"><i class="layui-icon">&#xe613;</i></a>
                                    </div>
                                </h2>
                                <table class="layui-hidden" id="treeTable" lay-filter="treeTable"></table>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </main>
@endsection
@section('footer')
    @include('Home.User.Common._form')
    <script>
        var editObj=null,ptable=null,treeGrid=null,tableId='treeTable',layer=null;
        layui.config({
            base: '/lib/layui/extend/'
        }).extend({
            treeGrid:'treeGrid'
        }).use(['jquery','treeGrid','layer'], function(){
            var $=layui.jquery;
            treeGrid = layui.treeGrid;//很重要
            layer=layui.layer;
            ptable=treeGrid.render({
                id:tableId
                ,elem: '#'+tableId
                ,url:'{{route('frame')}}'
                ,cellMinWidth: 100
                ,idField:'id'//必須字段
                ,treeId:'id'//树形id字段名称
                ,treeUpId:'belong'//树形父id字段名称
                ,treeShowName:'uid'//以树形式显示的字段
                ,heightRemove:[".dHead",10]//不计算的高度,表格设定的是固定高度，此项不生效
                ,width:'100%'
                ,height:'100%'
                ,isFilter:false
                ,iconOpen:true//是否显示图标【默认显示】
                ,isOpenDefault:false//节点默认是展开还是折叠【默认展开】
                ,loading:true
                ,method:'post'
                ,cols: [[
                    {field:'id', width: 150, title: 'ID'}
                    ,{field:'uid', width: 150,title: '姓名', align:'left',templet: function(full){
                            var username = full.uid;
                            if(full.user){
                                username = full.user.username;
                            }
                            return username;
                        }}
                    ,{field:'branch_id', width: 150,title: '所属部门',templet: function(full){
                            var branch = full.branch_id;
                            if(full.branch){
                                branch = full.branch.name;
                            }
                            return branch;
                        }}
                    ,{field:'level', width: 150,title: '职级',templet: function(full){
                            var level = full.level;
                            switch(level)
                            {
                                case 1:
                                    level = '经理';
                                    break;
                                case 2:
                                    level = '主管';
                                    break;
                                case 3:
                                    level = '员工';
                                    break;
                                default:
                                    level = '未知';
                            }
                            return level;
                        }}
                    ,{title: '操作', width: 300, style:'text-align:right;'
                        ,templet: function(full){
                            var html='';
                            if(full.level != 3){
                                var addBtn='<a class="layui-btn layui-btn-primary layui-btn-xs" onclick="open_button(\'{{route('frame_add')}}/'+full.id+'\',\'添加下属\',600,400)">添加下属</a>';
                            }else{
                                var addBtn='<a class="layui-btn layui-btn-primary layui-btn-xs" onclick="open_button(\'{{route('frame_add')}}/'+full.id+'\',\'添加同级成员\',600,400)">添加同级</a>';
                            }
                            var editBtn='<a class="layui-btn layui-btn-normal layui-btn-xs" onclick="open_button(\'{{route('frame_edit')}}/'+full.id+'\',\'编辑\',600,400)">编辑</a>';
                            if(full.level == 1){
                                var delBtn='<a class="layui-btn layui-btn-disabled layui-btn-xs">删除</a>';
                            }else{
                                var delBtn='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                            }

                            return addBtn+editBtn+delBtn;
                        }
                    }
                ]]
                ,isPage:false
                ,parseData:function (res) {//数据加载后回调
                    return res;
                }
                ,onClickRow:function (index, o) {
                }
                ,onDblClickRow:function (index, o) {
                }
            });

            treeGrid.on('tool('+tableId+')',function (obj) {
                if(obj.event === 'del'){//删除行
                    del(obj);
                }
            });
        });

        function del(obj) {
            layer.confirm("你确定删除 "+obj.data.user.username+" 吗？如果存在下级节点则将一并删除，此操作不能撤销！", {icon: 3, title:'提示'},
                function(index){//确定回调
                    $.ajax({
                        type: 'get',
                        url: '{{route('frame_del')}}/'+obj.data.id,
                        dataType: 'json',
                        success: function(data){
                            if(data.code){
                                layer.close(index);
                                obj.del();
                            }else{
                                layer.msg(data.msg,{icon: 5,time:1000});
                            }
                        },
                        error:function() {
                            layer.msg('服务器错误!',{icon: 5,time:1000});
                        }
                    });
                },function (index) {//取消回调
                    layer.close(index);
                }
            );
        }

    </script>
@endsection